<template>
  <div>
    <el-card style="max-width: 90vw">
      <el-form label-position="right" label-width="auto" :model="form" style="max-width: 600px">
        <h2 class="card-header">
          <span>学生已选题</span>
        </h2>
        <el-form-item label="题目名称">
          <el-input v-model="form.titleName" disabled />
        </el-form-item>
        <el-form-item label="题目来源">
          <el-input v-model="form.titleSource" disabled />
        </el-form-item>
        <el-form-item label="功能要求">
          <el-input v-model="form.titleRequirement" disabled />
        </el-form-item>
        <el-form-item label="技术要求">
          <el-input v-model="form.technicalRequirement" disabled />
        </el-form-item>
        <el-form-item label="老师">
          <el-input v-model="form.teacherName" disabled />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onDelete">取消选题</el-button>
          <!-- <el-button @click="clean">清空</el-button> -->
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Notice",
  data() {
    return {
      form: {},
      rules: {
        isNull: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ]
      }
    }
  },
  created() {
    this.load()
  },
  methods: {
    onDelete() {
      this.$confirm('您确定取消吗？', '取消选题', { type: "warning" }).then(e => {
        let user = JSON.parse(sessionStorage.getItem('user'))
        this.$request.get('/graduation/deleteTopic', { params: { userId: user.id } }).then(res => {
          if (res.code === 200) {
            // console.log(res);
            this.$message.success('取消成功')
            this.$router.push('/home/select')
          } else {
            this.$message.error(res.msg)
          }
        }).catch(err => {
          this.$message.error('提交错误')
        })
        this.clean()
      })
    },
    load() {
      let user = JSON.parse(sessionStorage.getItem('user'))
      this.$request.get('/graduation/getStudentTopic', { params: { userId: user.id } }).then(res => {
        if (res.code === 200) {
          // console.log(res.data);
          this.form = res.data
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error('提交错误')
      })
    },
    clean() {
      this.form = {}
    }
  }
}
</script>

<style scoped>
.card-header {
  margin-bottom: 20px;
}
</style>
